package com.gljx.web.service.impl;

import com.gljx.util.IsChinese;
import com.gljx.web.Entity.Person;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.PersonMapper;
import com.gljx.web.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PersonServiceImpl extends CommonDao implements PersonService {

	@Autowired
	private PersonMapper personMapper;


	/**
	 * 调用存储过程查询人员
	 * @createTime 2017-11-5 4:20 pm
	 * @author zyq.
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Person> selectPerson(String psql) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
							map.put("Psql", psql);
							map.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);
		this.getSqlSession().select("com.gljx.web.dao.PersonMapper.selectPerson", map, null);
		return (List<Person>) map.get("v_cursor");
	}


	/**
	 * 根据姓名查询人员记录
	 * @createTime 2017-11-7 10:20 am
	 * @author zyq.
	 * @return
	 */
	@Override
	public List<Person> selectPersonByName(String name) {
		// TODO Auto-generated method stub
		Map map = new HashMap();
			map.put("name",name);
			map.put("isChinese",IsChinese.isChinese(name));
		return personMapper.selectPersonByName(map);
	}

	@Override
	public List<Person> selectPersonForName(String name,String remark,String companyId ){

		Map map = new HashMap();
		map.put("name",name);
		map.put("isChinese",IsChinese.isChinese(name));
		map.put("remark",remark);
		map.put("companyId",companyId);
		return personMapper.selectPersonForName(map);

	}

	@Override
	public List<Person> selectPersonForByName(String name,String companyId ){

		Map map = new HashMap();
		map.put("name",name);
		map.put("isChinese",IsChinese.isChinese(name));
		map.put("companyId",companyId);
		return personMapper.selectPersonForByName(map);

	}

	@Override
	public List<Person> selectPersonForByCarId(String carId) {
		return personMapper.selectPersonForByCarId(carId);
	}

	/**
	 * 根据FID查询人员记录
	 * @createTime 2017-11-7 10:20 am
	 * @author zyq.
	 * @return
	 */
	@Override
	public Person selTrainTypeById(String string) {
		// TODO Auto-generated method stub
		return  personMapper.selTrainTypeById(string);
	}

	/**
	 *取分页数据    dmz 20160921
	 *@param pindex 页码
	 *@param psql SQL语句，需要带 rownum rn 例如：select rownum rn,t.* from zzda t
	 *@param psize 每页记录数
	 * */
	@Override
	public Map<String, Object> selectPage(int pindex, String psql, int psize) {
		  Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Pindex", pindex);
	       paramMap.put("Psql", psql);
	       paramMap.put("Psize", psize);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
	       this.getSqlSession().select("com.gljx.web.dao.PersonMapper.pagemap", paramMap, null);
	       return  paramMap;
	}

	/**
	 * 取记录总数      dmz 20160921
	 * @param psql   SQL语句
	 * @param Pcount 记录总数
	 * @return
	 */
	@Override
	public Map<String, Object> selectPageCount(String psql) {
		   Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Psql", psql);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       this.getSqlSession().select("com.gljx.web.dao.PersonMapper.pagecount", paramMap, null);
	       return paramMap;
	}


	/**
	 * 实现添加
	 */
	@Override
	public void addPerson(Person person) {
		// TODO Auto-generated method stub
		personMapper.insertSelective(person);
	}


	/**
	 * 实现都删除
	 */
	@Override
	public void deletePersonByFid(String fid) {
		// TODO Auto-generated method stub
		personMapper.deleteByPrimaryKey(fid);
	}


	/**
	 * 实现根据fid查询
	 */
	@Override
	public Person queryPersonByFid(String fid) {
		// TODO Auto-generated method stub
		return personMapper.selectPersonByFid(fid);
	}


	/**
	 * 实现修改
	 */
	@Override
	public void modifyPerson(Person person) {
		// TODO Auto-generated method stub
		personMapper.updateByPrimaryKeySelective(person);
	}

	/**
	 * 根据组织id查找人员
	 */
	@Override
	public List<Person> selPersionByFcomanyid(String fcomanyid) {
		// TODO Auto-generated method stub
		return personMapper.selPersionByFcomanyid(fcomanyid);
	}

    //传入 科目 1 或 2  车型 A1 或 A2查询教练列表
    @Override
	public List<Person> queryPersonList(String carType, String kemu, String fcompanyid) {
		return personMapper.selectPersonList(carType, kemu, fcompanyid);
    }

    //查询所有的职员
	@Override
	public List<Person> queryPersonListAsAllPerson(String fcompanyid) {
		return personMapper.selectPersonListAsAllPerson(fcompanyid);
	}

    @Override
    public Person selectPersonAsNo(String yyjlNo) {
        List<Person> personList = personMapper.selectPersonAsNo(yyjlNo);
        if (personList.isEmpty()) {
            return null;
        } else {
            return personMapper.selectPersonAsNo(yyjlNo).get(0);
        }
    }

	@Override
	public List<Person> selectPersonByrandom(String kmnumber) {
		// TODO Auto-generated method stub
		return personMapper.selectPersonByrandom(kmnumber);
	}


	@Override
	public List<Person> selectWeiXinTjrList(String fcomanyid,
											 String name,
											 int pageSize,
											 int pageNum) {
		int begin = pageSize*pageNum+1;
		int end = pageSize*(pageNum+1);
		return personMapper.selectWeiXinTjrList(fcomanyid, name ,begin,end);
	}

}
